#region Copyright RenGuiYou. All rights reserved.

//=====================================================
// NeatlyFrameWork
// Author:      RenGuiyou
// Feedback: 	mailto:750539605@qq.com
//=====================================================

#endregion

using System;
using System.Collections.Generic;
using Pandora;
using PandoraEditor;
using UnityEditor;
using UnityEngine;

namespace NeatlyEditor
{
    public static class NeatlyPackerMenu
    {
        private const string TITLE = "NeatlyPacker/";
        private const string TITLE_SWITCH_BUILD_TARGET = "NeatlyPacker/Switch Build Target/";
        private const string TITLE_WINDOWS = "NeatlyPacker/Win64/";
        private const string TITLE_ANDROID = "NeatlyPacker/Andorid/";
        private const string TITLE_IOS = "NeatlyPacker/iOS/";
        private const string TITLE_WEBGL = "NeatlyPacker/WebGL/";

        #region BuildTarget

        [MenuItem(TITLE_SWITCH_BUILD_TARGET + "Android", false, 1)]
        public static void SwitchBuildTargetAndroid()
        {
            EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Android, BuildTarget.Android);
        }

        [MenuItem(TITLE_SWITCH_BUILD_TARGET + "iOS", false, 2)]
        public static void SwitchBuildTargetIOS()
        {
            EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.iOS, BuildTarget.iOS);
        }

        [MenuItem(TITLE_SWITCH_BUILD_TARGET + "Win64", false, 3)]
        public static void SwitchBuildTargetWin64()
        {
            EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Standalone, BuildTarget.StandaloneWindows64);
        }

        [MenuItem(TITLE_SWITCH_BUILD_TARGET + "WebGL", false, 4)]
        public static void SwitchBuildTargetWebGL()
        {
            EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.WebGL, BuildTarget.WebGL);
        }

        #endregion

        #region Assets

        [MenuItem(TITLE + "清空bundle目录", false, 100)]
        public static void ClearAssetBundleFolder()
        {
            PdrFileUtil.DeleteDirectory(NeatlyEditorConfig.PATH_TEMP);
        }

        [MenuItem(TITLE + "build lua", false, 101)]
        public static void BuildLua()
        {
            AssetBundleImport.Init();
            NeatlyAssetPacker.BuildLua();
        }

        // [MenuItem(TITLE + "build lua(source)", false, 102)]
        public static void BuildLuaSource()
        {
            AssetBundleImport.Init();
            NeatlyAssetPacker.BuildLuaSource();
        }

        [MenuItem(TITLE + "build shader variant", false, 103)]
        public static void BuildShaderVariant()
        {
            NeatlyShaderCollection.GenShaderVariant();
        }

        [MenuItem(TITLE + "build AssetBundle", false, 104)]
        public static void BuildAssetBundle()
        {
            AssetBundleImport.Init();
            NeatlyAssetPacker.BuildAssetBundle();
            NeatlyAssetPacker.BuildAssetsHash();
        }

        [MenuItem(TITLE + "build Assets Hash", false, 105)]
        public static void BuildAssetsHash()
        {
            NeatlyAssetPacker.BuildAssetsHash();
        }

        [MenuItem(TITLE + "build All Assets", false, 106)]
        public static void BuildAllAsset()
        {
            NeatlyAssetPacker.BuildAllAsset();
        }

        // [MenuItem(TITLE + "build All Assets (source lua)", false, 107)]
        public static void BuildAllAssetSourceLua()
        {
            NeatlyAssetPacker.BuildAllAssetSourceLua();
        }

        [MenuItem(TITLE + "同步内网CDN", false, 201)]
        public static void CopyToServerCDN()
        {
            NeatlyLocalServerHelper.AssetToLocalServer();
        }

        [MenuItem(TITLE + "构建内网热更包", false, 202)]
        public static void BuildHotfix()
        {
            //设置下一个版本
            BuildSetting.SaveAll();
            NeatlyAssetPacker.BuildAllAsset();
            NeatlyLocalServerHelper.AssetToLocalServer();
        }

        #endregion

        #region Windows

        [MenuItem(TITLE_WINDOWS + "打包EXE", false, 301)]
        public static void BuildForWindows()
        {
            NeatlyProjectPacker.WindowsExportEXE();
        }

        [MenuItem(TITLE_WINDOWS + "发布内网", false, 301)]
        public static void CopyEXEToCDN()
        {
            NeatlyLocalServerHelper.PackageWin64ToLocalServer();
        }

        [MenuItem(TITLE_WINDOWS + "打包-发布内网", false, 301)]
        public static void BuildEXEAndCopy()
        {
            NeatlyProjectPacker.WindowsExportEXE();
            NeatlyLocalServerHelper.PackageWin64ToLocalServer();
        }

        #endregion

        #region Android

        [MenuItem(TITLE_ANDROID + "导出Gradle工程", false, 302)]
        private static void AndroidExportGradle()
        {
            NeatlyProjectPacker.AndroidExportGradle();
        }

        [MenuItem(TITLE_ANDROID + "打包Apk", false, 303)]
        public static void AndroidExportApk()
        {
            AndroidExportGradle();
            NeatlyProjectPacker.AndroidExportApk();
        }
        #endregion

        #region IOS

        [MenuItem(TITLE_IOS + "导出XCode工程", false, 304)]
        public static void IOSExport()
        {
            NeatlyProjectPacker.IOSExport();
        }

        [MenuItem(TITLE_IOS + "打包ipa", false, 303)]
        public static void IOSExportIpa()
        {
            IOSExport();
            NeatlyProjectPacker.IOSExportIpa();
        }

        #endregion

        #region WebGL

        [MenuItem(TITLE_WEBGL + "导出WebGL工程", false, 401)]
        private static void WebGLExportProject()
        {
            NeatlyProjectPacker.WebGLExportProject();
        }

        #endregion

        [MenuItem(TITLE + "Import PlayerSettings", false, 601)]
        public static void SetPlayerSetting()
        {
            NeatlyProjectPacker.SetPlayerSetting();
        }

        [MenuItem(TITLE + "Import WeChatPlayerSettings", false, 601)]
        public static void SetWeChatPlayerSetting()
        {
            NeatlyProjectPacker.SetWeChatPlayerSetting();
        }

        [MenuItem(TITLE + "AssetBundle检测依赖", false, 701)]
        public static void CheckAssetBundle()
        {
            NeatlyAssetBundleCheck.CheckAssetBundleDependency();
        }
    }
}